const baseConfig = require('./webpack.base.config.js')
const { merge } = require('webpack-merge');
// const TerserWebpackPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const webpack = require('webpack');

module.exports = merge(baseConfig, {
  mode: 'production',

  devtool: 'source-map',

  module: {
    rules: [
      {
        test: /\.less$/i,
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader',
          'less-loader',
        ],
      },
      {
        test: /\.css$/i,
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader',
        ],
      },
    ]
  },

  plugins: [
    new webpack.DefinePlugin({
      SERVER_URL: JSON.stringify("http://api.zmaolong.cn"),

    }),
    new MiniCssExtractPlugin({
      filename: 'css/main.css',
    }),
  ],

  optimization: {
    // minimize: false, // 禁用压缩
    minimizer: [
      // 在 webpack@5 中，你可以使用 `...` 语法来扩展现有的 minimizer（即 `terser-webpack-plugin`），将下一行取消注释
      `...`,
      new CssMinimizerPlugin(),
      // new TerserWebpackPlugin({
      //   terserOptions: {
      //     compress: false, // 禁用Terser的压缩功能
      //     mangle: false, // 禁用变量名混淆
      //     output: {
      //       beautify: true, // 启用更可读的输出
      //       comments: true, // 保留注释
      //     },
      //   },
      //   extractComments: false, // 不将注释提取到单独的文件
      // }),
    ],
  },

})